﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using Catel.Data;

namespace LprConfiger.Models
{
    /// <summary>
    /// 监控点的基本信息，这里是全局性的信息。
    /// </summary>
#if !SILVERLIGHT
    [Serializable]
#endif
    public class StationInfo : DataObjectBase<StationInfo>
    {
        #region Variables
        #endregion

        #region Constructor & destructor
        /// <summary>
        /// Initializes a new object from scratch.
        /// </summary>
        public StationInfo() { }

#if !SILVERLIGHT
        /// <summary>
        /// Initializes a new object based on <see cref="SerializationInfo"/>.
        /// </summary>
        /// <param name="info"><see cref="SerializationInfo"/> that contains the information.</param>
        /// <param name="context"><see cref="StreamingContext"/>.</param>
        protected StationInfo(SerializationInfo info, StreamingContext context)
            : base(info, context) { }
#endif
        #endregion

        #region Properties
        // TODO: Define your custom properties here using the dataprop code snippet

        /// <summary>
        /// 序列号.
        /// </summary>
        public string SN
        {
            get { return GetValue<string>(SNProperty); }
            set { SetValue(SNProperty, value); }
        }

        /// <summary>
        /// Register the SN property so it is known in the class.
        /// </summary>
        public static readonly PropertyData SNProperty = RegisterProperty("SN", typeof(string), "");

        /// <summary>
        /// 注册码.
        /// </summary>
        public string RegistrationCode
        {
            get { return GetValue<string>(RegistrationCodeProperty); }
            set { SetValue(RegistrationCodeProperty, value); }
        }

        /// <summary>
        /// Register the RegistrationCode property so it is known in the class.
        /// </summary>
        public static readonly PropertyData RegistrationCodeProperty = RegisterProperty("RegistrationCode", typeof(string), "");


        /// <summary>
        /// 设备IP.
        /// </summary>
        public string MachineIp
        {
            get { return GetValue<string>(MachineIpProperty); }
            set { SetValue(MachineIpProperty, value); }
        }

        /// <summary>
        /// Register the MachineIp property so it is known in the class.
        /// </summary>
        public static readonly PropertyData MachineIpProperty = RegisterProperty("MachineIp", typeof(string), "");


        /// <summary>
        /// 设备当前时间.
        /// </summary>
        public DateTime MachineTime
        {
            get { return GetValue<DateTime>(MachineTimeProperty); }
            set { SetValue(MachineTimeProperty, value); }
        }

        /// <summary>
        /// Register the MachineTime property so it is known in the class.
        /// </summary>
        public static readonly PropertyData MachineTimeProperty = RegisterProperty("MachineTime", typeof(DateTime), DateTime.MinValue);

        /// <summary>
        /// 监控点编号.
        /// </summary>
        public string StationId
        {
            get { return GetValue<string>(StationIdProperty); }
            set { SetValue(StationIdProperty, value); }
        }

        /// <summary>
        /// Register the StationId property so it is known in the class.
        /// </summary>
        public static readonly PropertyData StationIdProperty = RegisterProperty("StationId", typeof(string), "");


        /// <summary>
        /// 监控点名称.
        /// </summary>
        public string StationName
        {
            get { return GetValue<string>(StationNameProperty); }
            set { SetValue(StationNameProperty, value); }
        }

        /// <summary>
        /// Register the StationName property so it is known in the class.
        /// </summary>
        public static readonly PropertyData StationNameProperty = RegisterProperty("StationName", typeof(string), "");


        #endregion

        #region Methods
        /// <summary>
        /// Validates the fields.
        /// </summary>
        protected override void ValidateFields()
        {
            // TODO: Implement any field validation of this object. Simply set any error by using the SetFieldError method
            if (string.IsNullOrEmpty(StationId))
            {
                var r = new FieldValidationResult("StationId", ValidationResultType.Error, "监控点编号为空");
                SetFieldValidationResult(r);
            }
        }

        /// <summary>
        /// Validates the business rules.
        /// </summary>
        protected override void ValidateBusinessRules()
        {
            // TODO: Implement any business rules of this object. Simply set any error by using the SetBusinessRuleError method
        }
        #endregion
    }
}
